# Maintainer: Sam L. Yes <samlukeyes123 at gmail dot com>
# Contributor: Andre Klitzing <aklitzing () gmail () com>

pkgname=msitools
pkgver=0.101
pkgrel=6
pkgdesc='Set of programs to inspect and build Windows Installer (.MSI) files'
arch=('loong64' 'x86_64')
url='https://wiki.gnome.org/msitools'
license=('LGPL' 'GPL')
depends=('libgsf' 'gcab' 'libxml2')
makedepends=('git' 'intltool' 'vala' 'meson' 'gobject-introspection' 'bash-bats')
_commit='17ebe3af1ea2a4495d9ed5159fefd8a98291dc60'
source=(
  "$pkgname::git+https://gitlab.gnome.org/GNOME/msitools.git#commit=$_commit"
  'skip-failing-test.patch'
  'remove-git-dirty-suffix.patch'
  'use-system-bats.patch'
)
b2sums=('SKIP'
        '7c688138af873eed0bb1ddefe2910d9bdedb9174cc38464685c4c3c84f0c07b8aaa687093e694a4fafb952c1c010fbc7f0d62f69104d4557f13b9124f93d4209'
        'c30a2302e8cd202ecd084aa3d371d73021bc4fa5af4f3591f70362a1be41c738cf148a552f46f729bd8fade3d0b81a57eafbfa9d1c980e2ab5eed6f57f65a0ac'
        '529341b24254226baafd62d234de9e04d338df9a96ef66b3efb7bf987c82abf98b24aa302bceeea69a2ce28fd305db3ab7efd02b9173277eb3de01533e5282cb')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # glibc 2.71 patch
  git cherry-pick --no-commit 18bc0b2ee79438b8e35c0769165a9a105e3792a0

  # make msidiff and msidump executable 
  git cherry-pick --no-commit 25c4353cf173cddeb76c0a2dd6621bcb753cabf8

  # skip failing test
  patch -p1 -i "$srcdir/skip-failing-test.patch"

  # remove -dirty suffix from pkgver
  patch -p1 -i "$srcdir/remove-git-dirty-suffix.patch"

  # use system bats (bash-bats)
  patch -p1 -i "$srcdir/use-system-bats.patch"
}

build() {
  arch-meson "$pkgname" build

  ninja -C build
}

check() {
  meson test -C build
}

package() {
  DESTDIR="$pkgdir" meson install -C build

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" "$pkgname/copyright"
}
